import {MyUrl} from "./Constant.ts";
import axios from "axios";

/**
 * Comments
 */
export class Comments {
    content: string = null;
    createdAt: string = null;
    id: number = null;
    replyId: number = null;
    songId: number = null;
    type: Type ;
    updatedAt: string = null;
    userId: number = null;

    constructor(id?, type?, userId?, replyId?, songId?, content?) {
        this.content = content;
        this.id = id;
        this.replyId = replyId;
        this.songId = songId;
        this.type = type;
        this.userId = userId;
    }

}

export enum Type {
    Comment = "comment",
    Reply = "reply",
}


export async function Comments_findCommentListFromCommentsBySongId(songId: number) {
    return await axios.get(MyUrl.COMMENTS_findCommentListFromCommentsBySongId, {
        params: {
            songId: songId,
        }
    }).then(res => {
        console.log(res.data);
        return res.data.data
    })
}

export async function Comments_findReplyListFromCommentsByReplyId(replyId: number) {
    return await axios.get(MyUrl.COMMENTS_findReplyListFromCommentsByReplyId, {
        params: {
            replyId: replyId,
        }
    }).then(res => {
        console.log(res.data);
        return res.data.data
    })
}

export async function Comments_addComments(comments: Comments) {
    return await axios.post(MyUrl.COMMENTS_addComments, JSON.stringify(comments), {
        headers: {
            "Content-Type": "application/json",
        }
    }).then(res => {
        console.log(res.data);
        return res.data
    })
}

export async function Comments_deleteCommentsById(id: number) {
    return await axios.delete(MyUrl.COMMENTS_deleteCommentsById, {
        params: {
            id: id,
        }
    }).then(res => {
        console.log(res.data);
        return res.data
    })
}





